/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



//public void update_HashTableArray(ArrayList<Hashtable> new_HT_Array )
package IpChat_For_Testing;

import java.util.*;
/**
 *
 * @author Wei Liang
 */
public class IpChat_Main {

    private static ArrayList<Hashtable> AL_HT = new ArrayList<Hashtable>();
    public static GUI gui = new GUI();
    private IpChat_Constructor callChat=null;

    public static String newIn=null;
    public static Boolean has_new_text=false;

    //constructor
      public IpChat_Main()
      {
           develop();
      }


       public IpChat_Main(ArrayList<Hashtable> new_HT_Array)
      {
           gui.setVisible(true);
           gui.setchatH();
           callChat= new IpChat_Constructor(new_HT_Array, this);
          // update_HashTableArray(new_HT_Array);
      }

    private  void develop(){

         /*****************************************************/
            Hashtable test = new Hashtable();
            /*Insert user attributes into Hashtable test*/
            test.put("username", "Lubin");
            test.put("ip", "172.17.38.247");
            test.put("level", new Integer(5));
            test.put("team", new Integer(1));
            /*Insert test into AL_HT*/
            AL_HT.add(test);
          
            Hashtable test2 = new Hashtable();

//            test2.put("username", "Fazam");
//            test2.put("ip", "172.17.190.105");
//            test2.put("level", new Integer(2));
//            test2.put("team", new Integer(2));
//            AL_HT.add(test2);

            Hashtable test3 = new Hashtable();

            test3.put("username", "Wei Liang");
            test3.put("ip", "172.17.158.156");
            test3.put("level", new Integer(2));
            test3.put("team", new Integer(2));
            AL_HT.add(test3);
            callChat= new IpChat_Constructor(AL_HT, this);

    }




    //<editor-fold desc="Methods">
     public static void sendT(String msgT)
     {   
        String temp = "T" + msgT;
        newIn=temp;
        has_new_text=true;
        System.out.flush();
        //callChat.clients[0].newtext(temp);

        System.out.println("@IpChat_Main. IpChat_Constructor.clientCount= "+ IpChat_Constructor.clientCount);
       // System.out.println("@IpChat_Main. callChat.port= "+ IpChat_Constructor.port);
        System.out.println("@IpChat_Main Message to send is: "+temp);
       System.out.println("@IpChat_Main. IpChat_Constructor.clients[0].clientname= "+IpChat_Constructor.clients[0].clientname);
        if(IpChat_Constructor.clientCount>0)
            for (int i=0;i <  IpChat_Constructor.clientCount ; i++)
                if(IpChat_Constructor.clients[i].Team.equals(ChatServer.ownTeamNumber) )
                    IpChat_Constructor.clients[i].newtext(temp);
          
     }


    public static void sendA(String msgA)
    {
        String temp = "A" + msgA;
        newIn=temp;
        has_new_text=true;

        System.out.println("@Call_Main. IpChat_Constructor.clientCount= "+ IpChat_Constructor.clientCount);
       // System.out.println("@Call_Main. callChat.port= "+ IpChat_Constructor.port);
        System.out.println("@Call_Main Message to send is: "+temp);
       System.out.println("@Call_Main. IpChat_Constructor.clients[0].clientname= "+IpChat_Constructor.clients[0].clientname);
        if(IpChat_Constructor.clientCount>0)
            for (int i=0;i <  IpChat_Constructor.clientCount ; i++)
                //if (IpChat_Constructor.clients[i].socket !=null)
                    IpChat_Constructor.clients[i].newtext(temp);

        
    }//</editor-fold>


    public void update_HashTableArray(ArrayList<Hashtable> new_HT_Array )

    {
        callChat.update_ht(new_HT_Array);
    }


    //<editor-fold desc="Main">
    public static void main(String[] args)
    {
           
            gui.setVisible(true);
            gui.setchatH();
            IpChat_Main mian=new IpChat_Main();
    }//</editor-fold>


}
